<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <div id="app">
      <com-a></com-a>
      <com-b></com-b>
  </div>
  <template id="tmp1">
      <div>
          <h2>{{msg}}</h2>
          <div>接受数据: <span>{{data}}</span></div>
          <button @click='send'>click</button>
      </div>
  </template>
  <script src="./vue.js"></script>
  <script>
      let eventBus = new Vue()

      const comB = {
          data() {
              return {
                  msg:"COMB 数据",
                  data:""
              }
          },
          methods: {
              send() {
                  eventBus.$emit("busB",this.msg)
              }
          },
          template: "#tmp1",
          mounted() {
              eventBus.$on("busA",(res)=>{
                this.data = res
              })
          }
      }

      const comA = {
          data() {
              return {
                  msg:"COMA 数据",
                  data:""
              }
          },
          methods: {
              send() {
                  eventBus.$emit("busA",this.msg)
              }
          },
          template: "#tmp1",
          mounted() {
              eventBus.$on("busB",(res)=>{
                this.data = res
              })
          }
      }

    var vm = new Vue({
      el:'#app',
      data:{
      },
      methods:{
      },
      components: {
          comA,
          comB
      }
     });
  </script>
</body>
</html>
